<?php
class Custom_Application_Resource_Translate
    extends Zend_Application_Resource_ResourceAbstract
{
    protected $_translate;

    public function init()
    {
        if (null === $this->_translate) {
            $options = $this->getOptions();

            if (!isset($options['data'])) {
                throw new Zend_Application_Resource_Exception(
                        'No translation source data provided.'
                );
            }

            $adapter = isset($options['adapter']) ?
                            $options['adapter'] : Zend_Translate::AN_ARRAY;

            $this->getBootstrap()->bootstrap('Locale');
            $locale = $this->getBootstrap()->getResource('Locale');

            if (isset($options['data']['directory'])) {
                $data = $options['data']['directory'] . $locale .
                        '/wenda_core'.$options['data']['fileExt'];
            } else {
                $data = '';
            }

            $translate = new Zend_Translate(
                $adapter, $data, $locale
            );

            $translate->directory = $options['data']['directory'];

            Zend_Registry::set($options['registry_key'], $translate);
            Zend_Form::setDefaultTranslator($translate);

            $this->_translate = $translate;
        }
        return $this->_translate;
    }
}
